package com.ithanwen.service.Impl;

import ch.qos.logback.classic.Logger;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ithanwen.mapper.DeptMapper;
import com.ithanwen.pojo.Dept;
import com.ithanwen.service.DeptService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * Created By tony
 * <br/>Date: 2025/7/10 09:37
 * <br/>Description:
 */
@Service
public class DeptServiceImpl implements DeptService { ;
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> findall() {
        LambdaQueryWrapper<Dept> queryWrapper = new QueryWrapper<Dept>().lambda();
        queryWrapper.select(Dept::getId,Dept::getName,Dept::getCreateTime,Dept::getUpdateTime)
                .orderByDesc(Dept::getUpdateTime);
        return deptMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteById(Integer deptId) {
        deptMapper.deleteById(deptId);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept findById(Integer deptId) {
        return deptMapper.selectById(deptId);
    }

    @Override
    public void update(Dept dept) {
        deptMapper.updateById(dept);
    }


}
